using Core;
using UnityEngine;

namespace g_gongjianta
{
    public class Wall : Unit, IAwake<TblDungeon.WallConf>
    {
        public TblDungeon.WallConf Conf1 { get; private set; }
        public TblWall.Conf Conf2 { get; private set; }

        public Anchor Anchor { get; private set; }

        public WallMainComponent Main { get; private set; }

        public void Awake(TblDungeon.WallConf t)
        {
            base.Awake();
            Conf1 = t;
            Conf2 = G.Table.GetSO<TblWall>().Find(t.Id);

#if UNITY_EDITOR
            gameObject.name = $"Wall_{Conf1.Id}_{InstanceId}";
#endif
            var visualParam = new VisualParam
            {
                Path = Global.WALL_PREFAB_PATH,
                Icon = Conf2.Icon,
            };

            Pos = new Vector2(Conf1.PosX, Conf1.Height * 0.5f - 0.5f);

            Add<VisualComponent, VisualParam>(visualParam);

            Main = Add<WallMainComponent>();

            Anchor = G.Factory.Create<Anchor, TblDungeon.WallConf>(Conf1);
            Anchor.Pos = new Vector2(Conf1.PosX, Conf1.Height);
        }
    }
}